﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Googler.DAL;
using HodhodNews.Aggregation;
using Googler.BLL;
using HodhodNews.Controllers;

namespace Googler.Web
{
    public partial class Aggregate : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            //var list = new GoogleAtomNewsAggregationProvider().Aggregate(new AggregationOptions()
            //{
            //    Keywords = this.Keywords
            //});

            if (Application["AggregationInProgress"] == null)
            {
                this.DoNewsAggregation();
            }
        }
        
        public void DoNewsAggregation()
        {
            try
            {
                Application["AggregationInProgress"] = "Yes";
                var aggregator = NewsAggregationProvider.Instance;
                var list = aggregator.Aggregate(new AggregationOptions()
                {
                    Keywords = new UserController().GetKeywords()
                });
            }
            finally
            {
                Application["AggregationInProgress"] = null;
            }
        }
    }
}